//
//  WaitCommentVC.m
//  ForestPack
//
//  Created by jimmy on 2018/8/10.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "WaitCommentVC.h"
#import "UIView+Utils.h"
#import "StarView.h"
#import "AddImgButton.h"

@interface WaitCommentVC ()<UITableViewDelegate, UITableViewDataSource,UINavigationControllerDelegate,UIImagePickerControllerDelegate,UIActionSheetDelegate,UITextFieldDelegate,CTAssetsPickerControllerDelegate,UINavigationBarDelegate,UITextFieldDelegate,UITextViewDelegate>

@property (nonatomic,strong)  BaseTableView  * tableView;
@property (nonatomic,strong)  YYStarView     * starView ;
@property (nonatomic,strong)  UITextView     * contentTextView;
@property (nonatomic,assign)  CGFloat          starCount;
@property (nonatomic,copy)    NSString       * contentStr;
@property (nonatomic, strong) NSMutableArray<UIImage *> *commentImageArray;
@property (nonatomic, strong) NSMutableArray<NSString *> *commentUrlArray;
@property (nonatomic, strong) NSMutableArray *tagArr;

@property (nonatomic,assign)  NSInteger       imageCount;
@property (nonatomic, copy)   NSString *currentTag;

@property (nonatomic,strong)  NSMutableDictionary  * valueDict;

@end

@implementation WaitCommentVC

- (NSMutableDictionary *)valueDict
{
    if (_valueDict == nil) {
        _valueDict = [[NSMutableDictionary alloc] init];
    }
    return _valueDict;
}

- (UITextView *)contentTextView
{
    if (_contentTextView == nil) {
        _contentTextView = [[UITextView alloc] init];
    }
    return _contentTextView;
}

- (YYStarView *)starView
{
    if (_starView == nil) {
        _starView = [[YYStarView alloc] init];
    }
    return _starView;
}

- (NSMutableArray *)tagArr
{
    if (_tagArr == nil) {
        _tagArr = [[NSMutableArray alloc] init];
    }
    return _tagArr;
}

- (NSMutableArray *)commentImageArray
{
    if (_commentImageArray == nil) {
        _commentImageArray = [[NSMutableArray alloc] init];
    }
    return _commentImageArray;
}

- (NSMutableArray *)commentUrlArray
{
    if (_commentUrlArray == nil) {
        _commentUrlArray = [[NSMutableArray alloc] init];
    }
    return _commentUrlArray;
}

- (void)viewDidLoad
{
    [super viewDidLoad];


    [self setTitle:@"待评价"];
    self.currentTag = @"";
    [self setTableViewUI];
    
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
    //设置成NO表示当前控件响应后会传播到其他控件上，默认为YES。
    tapGestureRecognizer.cancelsTouchesInView = NO;
    //将触摸事件添加到view上
    [self.view addGestureRecognizer:tapGestureRecognizer];

}

-(void)keyboardHide:(UITapGestureRecognizer*)tap{
    [self.contentTextView resignFirstResponder];
}

-(void)addPics
{
    self.imageCount = 9 - self.commentImageArray.count;
    if (self.imageCount == 0) {
        return;
    }
    [self alterIconPortrait];
}

-(void)submitClick
{
    if (self.contentTextView.text.length <= 0 || self.commentImageArray.count <= 0 || self.starView.starScore <= 0) {//|| self.tagArr.count <= 0
        [HttpManager showNoteMsg:@"请把信息补充完整"];
        return;
    }
    [self uploadPics];
}

-(void)uploadPics
{
    WeakObj(self);
    [HttpManager uploadImageArr:selfWeak.commentImageArray success:^(id successResponse) {
        selfWeak.commentUrlArray = successResponse;
        [selfWeak requestdata];
    }];
}

-(void)requestdata
{
    if (self.commentUrlArray.count <= 0) {
        return;
    }
    NSString * main_pic = @""; /// [0], [1]
    for (NSString * urlStr in self.commentUrlArray) {
        if ([main_pic isEqualToString:@""]) {
            main_pic = urlStr;
        }else{
            main_pic = [NSString stringWithFormat:@"%@,%@",main_pic, urlStr]; /// [0], [1]
        }
    }
    
//    if (self.tagArr.count <= 0) {
//        return;
//    }
    NSString *tag = @"";
    for (NSString *str in self.tagArr) {
        tag = [tag stringByAppendingString:[NSString stringWithFormat:@",%@",str]];
    }
    if (tag.length > 0) {
        tag = [tag substringFromIndex:1];
    }
    
//    NSInteger starScore = [[self.valueDict valueForKey:@"starScore"] integerValue];
//    NSString *commentStr = [self.valueDict valueForKey:@"commentStr"];
    
    NSString *url = [NSString stringWithFormat:@"%@app/order_review",REQUESTHEADER];//添加商品
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setValue:[FPLoginAndRegisterTools getToken] forKey:@"token"];
    [dict setValue:@(self.starCount) forKey:@"quality_star"];//完成质量
    [dict setValue:@(self.starCount) forKey:@"speed_star"];//工作速度
    [dict setValue:@(self.starCount) forKey:@"server_star"];//服务态度
    [dict setValue:@(self.shop_id) forKey:@"shop_id"];//店铺id
    [dict setValue:@(self.order_id) forKey:@"order_id"];//订单id
    [dict setValue:@(self.order_no) forKey:@"order_no"];//订单号
    [dict setValue:@(self.goods_id) forKey:@"goods_id"];//订单商品id
    [dict setValue:self.contentStr forKey:@"content"];//内容
    [dict setValue:@"" forKey:@"label"];//评论标签（两个标签之间以逗号隔开）
    [dict setValue:main_pic forKey:@"pic"];//详情图（两个url之间以逗号隔开）
    [HttpManager postHttpRequestByPost:url andParameter:dict success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            [HttpManager showNoteMsg:@"提交成功"];
            dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC));
            dispatch_after(delayTime, dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:true];
            });
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

#pragma mark----- 选择弹出框
-(void)alterIconPortrait
{
    //弹出提示框
    __weak typeof(self)weakSelf = self;
    //初始化提示框
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    //按钮：拍摄
    [alert addAction:[UIAlertAction actionWithTitle:@"拍摄" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [weakSelf openCamare];
    }]];
    //按钮：从手机相册选择
    [alert addAction:[UIAlertAction actionWithTitle:@"从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
        [weakSelf openAlbum];
    }]];
    //按钮：取消，类型：UIAlertActionStyleCancel
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
}
#pragma mark - 打开相册
-(void)openAlbum
{
    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
        
        if (status != PHAuthorizationStatusAuthorized) {
            return ;
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            // init Picker弹出图片选择界面
            CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init];
            //隐藏空相册
            picker.showsEmptyAlbums = NO;
            //允许显示图片选中后的顺序
            picker.showsSelectionIndex = YES;
            //选择需要弹出的相册，一般我们只需要弹出相机胶卷和自定义相册即可
            picker.assetCollectionSubtypes = @[
                                               @(PHAssetCollectionSubtypeSmartAlbumUserLibrary),
                                               @(PHAssetCollectionSubtypeAlbumRegular)
                                               ];
            // picker delegate
            picker.delegate = self;
            
            // present picker
            [self presentViewController:picker animated:YES completion:nil];
            
        });
    }];
    
}

#pragma mark - 打开相机
-(void)openCamare
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.allowsEditing = YES;
    picker.delegate = self;
    
    [self presentViewController:picker animated:YES completion:nil];
    
}

#pragma mark - UIImagePickerControllerDelegate  图片处理
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    
    NSLog(@"Picker returned successfully.");
    //    将选择的图片在imageView上显示
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    
    [self.commentImageArray addObject:image];
    [self.tableView reloadData];
    //处理完毕，回到个人信息页面
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    
    NSLog(@"Picker was cancelled");
    [picker dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - 设置图片最多选九张
-(BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldSelectAsset:(PHAsset *)asset
{
    NSInteger max = self.imageCount;
    if (picker.selectedAssets.count < max) return YES;
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注意" message:[NSString stringWithFormat:@"最多选择%ld张图片",(long)max] preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    [alert addAction:action];
    //一定要用picker 不能用self 因为当前显示在最上面的控制器是picker 而不是self
    [picker presentViewController:alert animated:YES completion:nil];
    
    return NO;
}

#pragma mark - 选择完毕的时候调用
- (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets
{
    // 关闭图片选择界面
    [picker dismissViewControllerAnimated:YES completion:nil];
    //选择图片时的配置项 (如果不写配置项 会导致请求的图片尺寸出现问题)
    PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
    options.resizeMode = PHImageRequestOptionsResizeModeExact;
    options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
    
    //遍历图片选择的图片显示成九宫格样式
    for (NSInteger i = 0; i < assets.count; i ++) {
        PHAsset *asset = assets[i];
        CGFloat scale = UIScreen.mainScreen.scale;
        CGSize size = CGSizeMake(asset.pixelWidth / scale, asset.pixelHeight / scale);
        
        //请求图片 (需要先用图片管理员请求图片数据 请求完成后 在block里添加图片)
        [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:size contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
            WeakObj(self);
            
            [selfWeak.commentImageArray addObject:result];
            if (i == assets.count - 1) {
                [self.tableView reloadData];
            }
        }];
    }
}

/** 移除某一张照片*/
- (void)removeImage:(UIButton *)button
{
    [self showAlert:button];
    
}

- (void)showAlert:(UIButton *)button
{
    WeakObj(self);
    //显示提示框
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil  message:@"删除已选择的图片"  preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault   handler:^(UIAlertAction * action) {
        //响应事件
            [selfWeak.commentImageArray removeObjectAtIndex:button.tag - 2000];
            [selfWeak.tableView reloadData];
        
        
        NSLog(@"action = %@", action);
    }];
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel   handler:^(UIAlertAction * action) {
        //响应事件
        NSLog(@"action = %@", action);
        
    }];
    [alert addAction:defaultAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:nil];
}

/** 重新加载照片*/
- (void)reload
{
    /** 刷新*/
    [self.tableView reloadData];
//    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];
//    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}

/** 重新加载照片*/
- (void)reloadDetail
{
    /** 刷新*/
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:4 inSection:0];
    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}

-(void)btnLong:(UILongPressGestureRecognizer *)gestureRecognizer{
    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"是否确认删除标签" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self.tagArr removeObjectAtIndex:gestureRecognizer.view.tag - 200];
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 1)] withRowAnimation:UITableViewRowAnimationNone];
        }];
        
        [alertController addAction:cancel];
        [alertController addAction:sure];
        
        [self presentViewController:alertController animated:YES completion:nil];
    }
}

- (void)addTag {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"请输入标签名称" message:nil preferredStyle:UIAlertControllerStyleAlert];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        [textField addTarget:self action:@selector(textFieldChange:) forControlEvents:UIControlEventEditingChanged];
    }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (self.currentTag.length == 0) {
            [HttpManager showNoteMsg:@"请输入标签名称"];
            return ;
        }
        [self.tagArr addObject:self.currentTag];
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 1)] withRowAnimation:UITableViewRowAnimationNone];
    }];
    
    [alertController addAction:cancel];
    [alertController addAction:sure];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)textFieldChange:(UITextField *)textField {
    self.currentTag = textField.text;
}

-(void)setTableViewUI
{
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CommentCell"];
    [self.view addSubview:self.tableView];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - ScreenX375(64);
    }else{
        return ScreenX375(15) + (_tagArr.count / 3 + 1) * ScreenX375(45) + ScreenX375(100);
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return ScreenX375(78);
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        
        UIImageView *leftImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, ScreenX375(22.5), ScreenX375(3), ScreenX375(23))];
        leftImageV.image = [UIImage imageNamed:@"红色矩形"];
        leftImageV.contentMode = UIViewContentModeScaleToFill;
        [view addSubview:leftImageV];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(leftImageV.right + ScreenX375(10), ScreenX375(22.5), ScreenX375(100), ScreenX375(23))];
        titleLabel.text = @"对评价打分";
        titleLabel.numberOfLines = 0;
        titleLabel.textColor = FONTCOLOR_BLACK;
        titleLabel.font = Kfont(18);
        titleLabel.textAlignment = NSTextAlignmentLeft;
        [view addSubview:titleLabel];
        
        //星级评价view
        WeakObj(self);
        YYStarView *starView = [[YYStarView alloc] initWithFrame:CGRectMake(titleLabel.right + ScreenX375(20), ScreenX375(22.5), ScreenX375(140), ScreenX375(23))];
        //StarView的类型，如果不设置，默认为Select类型
        starView.type = StarViewTypeSelect;
        //星级评分，如果不设置，默认为0分（一般只有在展示时会设置这个属性）
        starView.starScore = 0;
        starView.starSpacing = 10;
        //每颗星的大小，如果不设置，则按照图片大小自适应
        starView.starSize = CGSizeMake(20, 20);
        //亮色星图片名称，如果不设置，则使用默认图片
        starView.starBrightImageName = @"评价";
        //暗色星图片名称，如果不设置，则使用默认图片
        //如果你需要设置亮星与暗星的高亮图片，也是支持的你只需要将高亮图片名改为正常图片加后缀"_highlighted"即可
        starView.starDarkImageName = @"评价灰色";
        self.starView.starScore = self.starCount;
        [view addSubview:starView];
        starView.starClick = ^ {
            NSLog(@"%f", self.starView.starScore);
            selfWeak.starCount = selfWeak.starView.starScore;
        };
        [view addSubview:self.starView];
        self.starView = starView;
        
        
        return view;
    }else{
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        UIImageView *leftImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, ScreenX375(22.5), ScreenX375(3), ScreenX375(23))];
        leftImageV.image = [UIImage imageNamed:@"红色矩形"];
        leftImageV.contentMode = UIViewContentModeScaleToFill;
        [view addSubview:leftImageV];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(leftImageV.right + ScreenX375(10), ScreenX375(22.5), ScreenX375(90), ScreenX375(23))];
        titleLabel.text = @"店铺标签";
        titleLabel.numberOfLines = 0;
        titleLabel.textColor = FONTCOLOR_BLACK;
        titleLabel.font = Kfont(18);
        titleLabel.textAlignment = NSTextAlignmentLeft;
        [view addSubview:titleLabel];
        
        UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, view.bottom - 1, SCREEN_WIDTH, ScreenX375(1))];
        lineLabel.backgroundColor = FONTCOLOR_LIGHTGRAY;
        [view addSubview:lineLabel];
        
        return view;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return ScreenX375(64);
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    ThemeButton *submitBtn = [[ThemeButton alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(10), SCREEN_WIDTH - ScreenX375(26), ScreenX375(44))];
    [submitBtn setTitle:@"提交" forState:UIControlStateNormal];
    [submitBtn addTarget:self action:@selector(submitClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:submitBtn];
    return view;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ContentCell"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ContentCell"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        for (UIView *subView in cell.subviews) {
            [subView removeFromSuperview];
        }
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(10), ScreenX375(180), ScreenX375(24))];
        label.textColor = FONTCOLOR_BLACK;
        label.text = @"请填写详细评价";
        label.font = Kfont(16);
        [cell addSubview:label];
        
        self.contentTextView = [[UITextView alloc] initWithFrame:CGRectMake(ScreenX375(13), label.bottom + ScreenX375(10), SCREEN_WIDTH - ScreenX375(26), ScreenX375(120))];
//        self.contentTextView.text = @"请填写详细评价";
//        self.contentTextView.textColor = FONTCOLOR_LIGHTGRAY;
        self.contentTextView.layer.cornerRadius = ScreenX375(5);
        self.contentTextView.layer.borderColor = LineColor.CGColor;
        self.contentTextView.layer.borderWidth = 1;
        self.contentTextView.clipsToBounds = YES;
        self.contentTextView.font = Kfont(14);
        self.contentTextView.delegate = self;
        self.contentTextView.text = self.contentStr;
        [cell addSubview:self.contentTextView];
        
//        [self.valueDict setValue:self.contentTextView.text forKey:@"commentStr"];
        
        CGFloat margin = (SCREEN_WIDTH - ScreenX375(26) - ScreenX375(330)) / 2;
        for (int i = 0; i < self.commentImageArray.count; i++) {
            
            CGFloat x = i % 3 * (ScreenX375(110) + margin) + ScreenX375(13);
            CGFloat y = i / 3 * ScreenX375(120) + ScreenX375(190);
            UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, ScreenX375(110), ScreenX375(110))];
            imageV.image = self.commentImageArray[i];
            imageV.userInteractionEnabled = YES;
            imageV.tag = 999;
            [cell addSubview:imageV];
            
            /** 为图片添加一个右上角的删除按钮*/
            UIButton *removeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            CGFloat removeX = ScreenX375(110) - ScreenX375(20);
            CGFloat removeW = ScreenX375(24);
            removeBtn.frame = CGRectMake(removeX, -12, removeW, removeW);
            [removeBtn setImage:[UIImage imageNamed:@"案例删除"] forState:UIControlStateNormal];
            [removeBtn addTarget:self action:@selector(removeImage:) forControlEvents:UIControlEventTouchUpInside];
            removeBtn.tag = i + 2000;
            [imageV addSubview:removeBtn];
        }
        
        if (self.commentImageArray.count != 9) {
            AddImgButton *addPicsBtn = [[AddImgButton alloc] initWithFrame:CGRectMake(self.commentImageArray.count % 3 * (ScreenX375(110) + margin) + ScreenX375(13), self.commentImageArray.count / 3 * ScreenX375(120) + ScreenX375(190), ScreenX375(110), ScreenX375(110))];
            [addPicsBtn addTarget:self action:@selector(addPics) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:addPicsBtn];
        }
        return cell;
    }else{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LabelCell"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LabelCell"];
        }
        
        for (int i = 0; i < _tagArr.count + 1; i++) {
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(13) + i % 3 * ScreenX375(104), ScreenX375(15) + i / 3 * ScreenX375(45), ScreenX375(94), ScreenX375(30))];
            button.backgroundColor = ThemeColor;
            button.layer.cornerRadius = ScreenX375(15);
            button.clipsToBounds = YES;
            button.tag = 200 + i;
            if (i < _tagArr.count) {
                [button setTitle:_tagArr[i] forState:UIControlStateNormal];
                UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(btnLong:)];
                longPress.minimumPressDuration = 0.5; //定义按的时间
                [button addGestureRecognizer:longPress];
            }else {
                [button setImage:[UIImage imageNamed:@"+副本"] forState:UIControlStateNormal];
                [button addTarget:self action:@selector(addTag) forControlEvents:UIControlEventTouchUpInside];
            }
            button.titleLabel.font = Kfont(14);
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [cell addSubview:button];
        }
        return cell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:false];
}

- (void)textViewDidChange:(UITextView *)textView
{
    self.contentStr = self.contentTextView.text;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.contentTextView resignFirstResponder];
}

@end
